package com.itheima.sms.service.impl;

import com.itheima.sms.common.MqConst;
import com.itheima.sms.mqtask.SmsSendTask;
import com.itheima.sms.service.SmsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService(timeout = 5000)
@Slf4j
public class SmsServiceImpl implements SmsService {

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    /**
     * @Author: JASON
     * @Date: 16:01 2021/1/18
     * @Parms [phone, content]
     * @ReturnType: void
     * @Description: 发送短信
    */
    @Override
    public void send(String phone, String content) {
        log.info("[短信-发送]phone：{}，content：{}",phone,content);
        //封装成任务发送到mq
        SmsSendTask task = new SmsSendTask(phone, content);
        //直接发送
        rocketMQTemplate.convertAndSend(MqConst.SMS_SEND_TOPIC,task);
        log.info("[短信-发送]短信发送任务放入任务队列"+task);

    }
}
